package com.samphanie.auiu.library.log;

import android.util.Log;

import androidx.annotation.NonNull;

import static com.samphanie.auiu.library.log.AuiuLogConfig.MAX_LENGTH;

/**
 * @author ZSY
 */
public class AuiuConsolePrinter implements AuiuLogPrinter {
    @Override
    public void print(@NonNull AuiuLogConfig config, int level, String tag, @NonNull String printString) {
        int length = printString.length();

        int countOfSub = length/MAX_LENGTH;

        if (countOfSub > 0) {
            int index = 0;

            for (int i = 0; i < countOfSub; i++) {
                Log.println(level, tag, printString.substring(index, index + MAX_LENGTH));
                index+=MAX_LENGTH;
            }

            if (index != length) {
                Log.println(level, tag, printString.substring(index, length));
            }
        } else {
            Log.println(level, tag, printString);
        }
    }
}
